package com.agileboot.api;

import com.alibaba.druid.util.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动程序 定制banner.txt的网站
 * <a href="http://patorjk.com/software/taag">http://patorjk.com/software/taag</a>
 * <a href="http://www.network-science.de/ascii/">http://www.network-science.de/ascii/</a>
 * <a href="http://www.degraeve.com/img2txt.php">http://www.degraeve.com/img2txt.php</a>
 * <a href="http://life.chacuo.net/convertfont2char">http://life.chacuo.net/convertfont2char</a>
 *
 * @author valarchie
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ComponentScan(basePackages = "com.agileboot.*")
public class ApiApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(ApiApplication.class, args);

        System.out.println("--------------------------------------------------------------");

        ConfigurableEnvironment env = application.getEnvironment();
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }

        System.out.println("\n----------------------------------------------------------\n\t" +
                "Application  is running! Access URLs:\n\t" +
                " - Local: http://localhost:" + port + path + "\n\t"
                +
                " - Network: http://" + ip + ":" + port + path + "\n\t"
                +
                " - swagger: http://" + ip + ":" + port + "/swagger-ui.html" + "\n\t"
                +
                "----------------------------------------------------------");
    }
}
